import axios from 'axios'
// import store from '@/store/index.js'
// import baseURL from './baseURL'

const http = {}


http.get = function(url, data) {
    return new Promise((resolve, reject) => {
        axios
            .get(url, data, options)
            .then(response => {
                console.log(response)
                if (response.code === 0) {
                    resolve(response.data)
                } else {
                    Message.error({
                        message: response.message
                    })
                    reject(response.message)
                }
            })
            .catch(e => {
                console.log(e)
            })
    })
}

http.post = function(url, data, options) {
    return new Promise((resolve, reject) => {
        axios
            .post(url, data, options)
            .then(response => {
                console.log(response)
                if (response.code === 0) {
                    resolve(response.data)
                } else {
                    Message.error({
                        message: response.message
                    })
                    reject(response.message)
                }
            })
            .catch(e => {
                console.log(e)
            })
    })
}

export default http
